<?php

namespace App\Http\Controllers\RbhMiniProgram;

use App\Http\Controllers\Controller;
use App\Models\BannerModel;
use App\Utils\ApiResponse;
use App\Utils\VerifyRequestInput;
use Illuminate\Http\JsonResponse;

class MiniProgramHomeController extends Controller
{
    use ApiResponse, VerifyRequestInput;

    /**
     *
     * @return JsonResponse
     */
    public function getHomeList(): JsonResponse
    {
        $collection = BannerModel::where('status', 1)->whereIn('position', [1,3])->get();
        $banners = [];
        $suppliers = [];
        foreach ($collection as $item) {
            $item->image = $item->image ? self::STORAGE_HOST . '/storage/' . $item->image : '';
            if ($item->position == 1)
                $banners[] = $item;
            else
                $suppliers[] = $item;
        }
        return $this->success(['banners' => $banners, 'suppliers' => $suppliers]);
    }
}
